//////////////////////////////////////////////////////page_withdrawalState//////////////////////////////////
$(document).on("pageInit", "#page_withdrawalState", function(e, pageId, $page) {
    my.givetitle('余额提现');
	 $.showIndicator();
            key=my.get_key(my.getCookie('token'));
            var info={'user_id':my.getCookie('id')};
            info=JSON.stringify(info);
            info=my.cryptoASEencrypt(info,key);
            //console.log(info);return;
            $.ajax({
                type:"post",
                url:api.getbankcard,
                data:{
                    'api_value':info
                },
                async:true,
                error:function(XMLHttpRequest){
                    console.log(XMLHttpRequest);
                     $.hideIndicator();
                    $.alert("请求失败，请刷新重试");
                },
                success:function(data){
                    if(data.match("err_code")!=null){
                        $.hideIndicator();
                        //console.log(JSON.parse(data).err_code);
                        switch(JSON.parse(data).err_code)
                        {
                            case 40003:
                                my.tokenExpire();
                                break;
                            case 50091:
                                $.alert(JSON.parse(data).err_msg);
                                //$.router.loadPage("checkBankCard.html");
                                $.router.load(checkBankCardUrl,true);
                            default:
                                $.alert(JSON.parse(data).err_msg);

                        }
                    }else{
                        data=JSON.parse(data);
                        data=JSON.parse(my.cryptoASEdencrypt(data.data,key));
                        //console.log(data);
                        $(".balancea_account").text(data.balancea_ccount);
                        $(".balancea_account_hidden").val(data.balancea_ccount);
                        $(".band_name").html(data.bank_name+'('+data.open_account+')');
                        $(".user_bankid").val(data.user_bankid);
                        $(".b_name").val(data.bank_name);
                        $(".b_cardid").val(data.open_account);
                        $.hideIndicator();

                    }
                }
            });

            $(".cancel").click(function(){
               // $.router.loadPage("home.html");
                $.router.load(homeUrl,true);
            });

            $(".subWithdrawal").click(function(){
                $.alert('您确认要申请提现么？',function(){
                    var withdrawalmoney = $(".withdrawalmoney").val();
                    var withdrawalpass = $(".withdrawalpass").val();
                    var balancea_account = $(".balancea_account_hidden").val();
                    if(balancea_account==0){
                        $.toast('账户余额为0不能提现');
                        return false;
                    }
                    if($.trim(withdrawalmoney)==''){
                        $.toast('请输入提现金额');
                        return false;
                    }
//                if(withdrawalmoney > balancea_account){
//                    $.toast('提现金额大于账户余额');
//                    return false;
//                }
                    if($.trim(withdrawalpass)==''){
                        $.toast('请输入支付密码');
                        return false;
                    }
                    var info={
                        'user_id':my.getCookie('id'),
                        'user_cash':$.trim(withdrawalmoney),
                        'user_paymentpass':$.trim(withdrawalpass),
                        'user_bankname': $(".b_name").val(),
                        'user_carcode': $(".b_cardid").val()
                    };
                    info=JSON.stringify(info);
                    info=my.cryptoASEencrypt(info,key).toString();
                    $.ajax({
                        type:"post",
                        url:api.withdrawals,
                        data:{
                            'api_value':info
                        },
                        async:true,
                        error:function(XMLHttpRequest){
                            console.log(XMLHttpRequest);
                            $.hideIndicator();
                            $.toast("请求失败，请刷新重试");
                        },
                        success:function(data){
                            if(data.match("err_code")!=null){
                                $.hideIndicator();
                                //console.log(JSON.parse(data).err_code);
                                switch(JSON.parse(data).err_code)
                                {
                                    case 40003:
                                        my.tokenExpire();
                                        break;
                                    case 50100:
                                        $.toast(JSON.parse(data).err_msg);
                                    case 50101:
                                        $.toast(JSON.parse(data).err_msg);
                                    case 50102:
                                        $.toast(JSON.parse(data).err_msg);
                                    case 50405:
                                        $.toast(JSON.parse(data).err_msg);
                                    case 50608:
                                        $.toast(JSON.parse(data).err_msg);
                                    default:
                                        $.toast(JSON.parse(data).err_msg);

                                }
                            }else{
                                data=JSON.parse(data);
                                data=JSON.parse(my.cryptoASEdencrypt(data.data,key));
                                console.log(data);
                                if(data.result_state==1){
                                    $.toast('提交成功');
                                   // $.router.loadPage("home.html");
                                    $.router.load(homeUrl,true);
                                }else{
                                    $.toast('提交失败');
                                }
                                $.hideIndicator();

                            }
                        }
                    });
                });

            });
});